package com.tanhua.server.service;

import com.tanhua.server.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

@Service
@Slf4j
public class UserService {

    @Autowired
    private RestTemplate restTemplate;

    @Value("${tanhua.sso.url}")
    private String tanhuaSSOurl;

    public User queryUserByToken(String token) {
        try {
            //拼接url
            String url = tanhuaSSOurl+"/user/"+token;

            User user = restTemplate.getForObject(url, User.class);
            //System.out.println(user);
            return user;
        } catch (RestClientException e) {
            log.error("查询sso，获取user失败");
        }
        return null;
    }

}
